package com.cbs.android.module.discussion.extension;

import com.cbs.android.module.discussion.DateFormatter;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

/**
 * Created by broche on 9/12/16.
 */
public class SimpleDateFormatter implements DateFormatter {
    @Override
    public String format(int timestamp) {
        String result;
        double timeInterval = System.currentTimeMillis() / 1000 - timestamp;
        if (timeInterval < 60) {
            result = "1分钟内";
        } else if (timeInterval < 3600) {//1小时内
            result = (int) timeInterval / 60 + "分钟前";
        } else if (timeInterval < 3600 * 3) {//3小时内
            result = (int) timeInterval / 3600 + "小时前";
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sdf.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai")));
            result = sdf.format(new java.util.Date(timestamp * 1000L));
        }
        return result;
    }
}
